<template>
  <div id="app">
    <div v-if="brandMsg === 0" style="text-align:center; margin:50px 0;">
      <van-loading type="spinner" color="#007AFF" />
    </div>
    <template v-else-if="brandMsg === 1">
      <router-view v-wechat-title="$route.meta.title"/>
    </template>
    <template v-else>
      <van-empty image="error" description="网络出错了～" />
    </template>
  </div>
</template>

<script>
import { getBrandInfo } from '@/api/account'
export default {
  data () {
    return {
      brandMsg: 0
    }
  },
  name: 'App',
  created () {
    const brandmsg = localStorage.getItem('BRANDMSG')
    if (brandmsg) {
      this.brandMsg = 1
    } else {
      const domainName = window.location.host
      getBrandInfo(domainName).then(res => {
        console.log('domainName', res)
        this.brandMsg = 1
        document.title = res.data.data.brand.brandName
        localStorage.setItem('BRANDMSG', JSON.stringify(res.data.data))
      }).catch(res => {
        console.log('catchDomainName', res)
        this.brandMsg = -1
      })
    }
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  box-sizing: border-box;
}
div{
  box-sizing: border-box;
}
.spaceBetween{
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.btnArea{
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translate(-50%,0);
}
.btnArea button{
  width: 200px;
  border-radius: 5px;
}
</style>
